package com.lanhai.ads;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpStatus;

@MapperScan("com.lanhai.ads.dao")
@SpringBootApplication
public class FnIgvStatisApplication {

    public static void main(String[] args) {
        SpringApplication.run(FnIgvStatisApplication.class, args);
    }

    /**
     * 解决前后端集成后，前端的router和后端的contoller path之间的矛盾。当刷新页面或直接输入path时，报`Whitelabel Error Page，This application has no explicit mapping for /error, so you are seeing this as a fallback。`
     * 参考：https://www.cxyzjd.com/article/Mr_EvanChen/83625082；https://www.codeleading.com/article/67134008368/
     * @return
     */
    @Bean
    public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer(){
        return factory -> {
            ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/index.html");
            factory.addErrorPages(error404Page);
        };
    }
}
